// =============================================================================
//  Spangles Analyzer
//
//  Copyright(c) 2008
//  See LICENSE.txt for licensing information.
// =============================================================================

package com.google.spangles.domain;

import java.util.HashSet;
import java.util.Set;

/**
 * (Description)
 * (Any invariants [conditions that are always true] )
 * (Usage instructions, and/or examples)
 * (TODOs, ASSUMPTIONs, etc.)
 * (Known Bugs)
 * (Concurrency strategy - not thread safe or how it's thread safe)
 * 
 * @author Chris
 */
public class Location
{
   int x;
   
   int y;

   /**
    * @param x
    * @param y
    */
   public Location(int x, int y)
   {
      this.x = x;
      this.y = y;
   }

   /* (non-Javadoc)
    * @see java.lang.Object#hashCode()
    */
   public int hashCode()
   {
      final int prime = 31;
      int result = 1;
      result = prime * result + x;
      result = prime * result + y;
      return result;
   }

   /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
   public boolean equals(Object obj)
   {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      final Location other = (Location) obj;
      if (x != other.x)
         return false;
      if (y != other.y)
         return false;
      return true;
   }

   /**
    * @return Returns the x.
    */
   public int getX()
   {
      return x;
   }

   /**
    * @return Returns the y.
    */
   public int getY()
   {
      return y;
   }

   /**
    * (Description - what the method does and why)
    * (Visibility decision, if not obvious)
    * (Pre/Post Conditions)
    * (Usage examples)
    * (Algorithmic notes)
    * (Concurrency issues)
    * @return
    */
   public Set<Location> getNeighbors()
   {
      Set<Location> results = new HashSet<Location>();
      
      results.add( new Location(x-1,y));
      results.add( new Location(x+1,y));
      
      if (((x+y)%2) == 0)
      {
         results.add( new Location(x,y+1));
      }
      else
      {
         results.add( new Location(x,y-1));
      }
         
      return results;
   }
   
   public String toString()
   {
      return "("+x+","+y+")";
   }   
}
